﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Alma.Models
{
    public class ComparatorCriterions
    {
        public string Name { get; set; }
        public string[] Values { get; set; }
        public string Unity { get; set; }
    }

    public class ComparatorModel
    {
        public List<ProductDetailsModel> productList { get; set; }
        public List<int> idList { get; set; }
        public string product1 { get; set; }
        public string product2 { get; set; }
        public ComparatorCriterions[] Criterions { get; set; }
        public ComparatorModel()
        {
            productList = new List<ProductDetailsModel>();
            idList = new List<int>();
        }

        public void BuildCriterions()
        {
            var crits = new Dictionary<string, ComparatorCriterions>();
            var i = 0;
            foreach (var p in productList)
            {
                foreach (var crit in p.CriterionList)
                {
                    if (!crits.ContainsKey(crit.Item1))
                    {
                        crits.Add(crit.Item1, new ComparatorCriterions() { Name = crit.Item1, Unity = crit.Item3, 
                            Values = new string[productList.Count] });                      
                    }
                    crits[crit.Item1].Values[i] = crit.Item2;
                }
                i += 1;
            }
            Criterions = crits.Values.ToArray();
        }
    }
}